package com.peng.leetcode.tree;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * FindBottomLeftValue
 * 513. 找树左下角的值
 * https://leetcode.cn/problems/find-bottom-left-tree-value/
 * <p>
 * Created on 2022/12/3
 *
 * @author lupeng
 */
public class FindBottomLeftValue {
    public int findBottomLeftValue(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int ans = 0;
        Queue<TreeNode> q = new ArrayDeque<>();
        q.offer(root);
        while (!q.isEmpty()) {
            TreeNode n = q.poll();
            if (n.right != null) {
                q.offer(n.right);
            }
            if (n.left != null) {
                q.offer(n.left);
            }
            ans = n.val;
        }
        return ans;
    }
}
